{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "20b92429-d022-45da-9740-85e5ce889cc4",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "   员工ID  迟到次数  早退次数  缺勤天数  加班小时数  平均每日工作时间  工作效能评分\n",
      "0  E001     6    11    10     53       7.9       4\n",
      "1  E002    19     6     8     55       7.0      16\n",
      "2  E003    14     8     4     32       9.3      24\n",
      "3  E004    10     7     0     23      11.6      80\n",
      "4  E005     7    11     2     51      10.2       2\n",
      "5  E006    20     1     9     10       9.4      92\n",
      "6  E007     6     0     7     48       6.6      32\n",
      "7  E008    18    15    10      7       9.7      91\n",
      "8  E009    10     6     5     35      11.9      84\n",
      "9  E010    10     6     7     37       6.8      24\n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "\n",
    "# 设置随机种子保证可重复性\n",
    "np.random.seed(42)\n",
    "\n",
    "# 生成100名员工的模拟数据\n",
    "data = {\n",
    "    '员工ID': [f'E{str(i).zfill(3)}' for i in range(1, 101)],\n",
    "    '迟到次数': np.random.randint(0, 21, 100),\n",
    "    '早退次数': np.random.randint(0, 16, 100),\n",
    "    '缺勤天数': np.random.randint(0, 11, 100),\n",
    "    '加班小时数': np.random.randint(0, 61, 100),\n",
    "    '平均每日工作时间': np.round(np.random.uniform(6, 12, 100), 1),\n",
    "    '工作效能评分': np.random.randint(1, 101, 100)\n",
    "}\n",
    "\n",
    "# 创建DataFrame\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "# 显示前10行\n",
    "print(df.head(10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "13776f82-7aaa-40e6-ab83-636d6fbaf094",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "       交易ID     客户ID        交易日期      交易金额 交易类型       账户余额 交易地区  客户年龄  客户信用评分  \\\n",
      "0  TXN01000  CUST039  2023-01-09  47178.21   工资   -1375.82   东北  35.0   736.0   \n",
      "1  TXN01001  CUST029  2023-12-10  46244.73   转账   73752.39   华东  64.0   322.0   \n",
      "2  TXN01002  CUST015  2023-05-09 -24821.77   转账   81039.35   华南  58.0   757.0   \n",
      "3  TXN01003  CUST043  2023-05-16   -275.15  NaN  146248.96   西部  66.0   382.0   \n",
      "4  TXN01004  CUST008  2023-03-04 -19912.17   还款   42680.71   华东  31.0   444.0   \n",
      "5  TXN01005  CUST021  2023-05-19 -21515.95   其他   28710.07   西部  32.0   384.0   \n",
      "6  TXN01006  CUST039  2023-03-22 -46311.31   还款    6983.32   西部  48.0   377.0   \n",
      "7  TXN01007  CUST019  2023-06-12  10956.43   其他   79946.04   华南  18.0   756.0   \n",
      "8  TXN01008  CUST023  2023-10-16       NaN   投资  134584.98   华北  70.0   300.0   \n",
      "9  TXN01009  CUST011  2023-09-18 -44852.12   转账    2220.66   东北  71.0   350.0   \n",
      "\n",
      "   是否异常交易  \n",
      "0       1  \n",
      "1       0  \n",
      "2       1  \n",
      "3       0  \n",
      "4       0  \n",
      "5       0  \n",
      "6       0  \n",
      "7       0  \n",
      "8       0  \n",
      "9       0  \n"
     ]
    }
   ],
   "source": [
    "import pandas as pd\n",
    "import numpy as np\n",
    "from datetime import datetime, timedelta\n",
    "\n",
    "# 设置随机种子保证可重复性\n",
    "np.random.seed(42)\n",
    "\n",
    "# 生成100条记录\n",
    "num_records = 100\n",
    "\n",
    "# 基础数据生成\n",
    "data = {\n",
    "    '交易ID': [f'TXN{str(i).zfill(5)}' for i in range(1000, 1000+num_records)],\n",
    "    '客户ID': np.random.choice([f'CUST{str(i).zfill(3)}' for i in range(1, 51)], num_records),\n",
    "    '交易日期': [(datetime(2023, 1, 1) + timedelta(days=np.random.randint(0, 365))).strftime('%Y-%m-%d') \n",
    "               for _ in range(num_records)],\n",
    "    '交易金额': np.round(np.random.uniform(-50000, 50000, num_records), 2),\n",
    "    '交易类型': np.random.choice(['工资', '购物', '投资', '转账', '还款', '其他'], num_records),\n",
    "    '账户余额': np.round(np.random.uniform(-10000, 200000, num_records), 2),\n",
    "    '交易地区': np.random.choice(['华东', '华北', '华南', '西部', '东北'], num_records),\n",
    "    '客户年龄': np.random.randint(18, 81, num_records),\n",
    "    '客户信用评分': np.random.randint(300, 851, num_records),\n",
    "    '是否异常交易': np.random.choice([0, 1], num_records, p=[0.9, 0.1])\n",
    "}\n",
    "\n",
    "# 创建DataFrame\n",
    "df = pd.DataFrame(data)\n",
    "\n",
    "# 故意添加一些缺失值\n",
    "for col in ['交易金额', '交易类型', '客户年龄', '客户信用评分']:\n",
    "    df.loc[df.sample(frac=0.05).index, col] = np.nan\n",
    "\n",
    "# 故意添加一些重复记录\n",
    "duplicates = df.sample(2)\n",
    "df = pd.concat([df, duplicates], ignore_index=True)\n",
    "\n",
    "# 显示前10行\n",
    "print(df.head(10))\n",
    "\n",
    "# 保存到CSV\n",
    "df.to_csv('financial_data.csv', index=False, encoding='utf-8-sig')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e7a5a0e3-e155-4de5-982d-b34ac6847391",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "yolo11",
   "language": "python",
   "name": "yolo11"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.16"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
